//
//  UserAccountSecurityController.m
//  CheekiOS
//
//  Created by mac on 2017/6/22.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserAccountSecurityController.h"
#import "UserAccountSecurityCell.h"
#import "UserSecurityController.h"//账户安全开启
#import "UserPhonebindingController.h"//更改
#import "UserPhoneChangeController.h"//新手机号绑定
#import "ForgetViewController.h"//修改密码
@interface UserAccountSecurityController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UserpersionlInfoModel *model;

@end

@implementation UserAccountSecurityController


-(void)viewWillAppear:(BOOL)animated{
    [self setNavgationBarHiddenNo];
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestDate) name:@"UserSecurityControllerNotification" object:nil];
    
    [self setNavgationBarHiddenNo];
    self.title = @"账户与安全";
    
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-49) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
    }
    
    [self requestDate];
}

-(void)requestDate{
    [HcardHttpmanager getPersionalInfosuccess:^(id sucess) {
        
        self.model = [UserpersionlInfoModel mj_objectWithKeyValues:sucess[@"res"]];
    
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
    }];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UserAccountSecurityCell *cell = [UserAccountSecurityCell cellWithTableView:tableView indexPath:indexPath];
    
    if (indexPath.row==0) {
        cell.backgroundColor = RGB(243, 243, 243);
    }
    
    cell.model = _model;
    
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 10;
    }else{
        return 55;
    }
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 1) {

        if(self.model.mobile.length!=0&&self.model.mobile!=nil){
            
            UserPhonebindingController *vc = [[UserPhonebindingController alloc] init];
            vc.mobileStr = self.model.mobile;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            UserPhoneChangeController *vc = [[UserPhoneChangeController alloc] init];
            vc.typeStr = @"1";
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }else if(indexPath.row == 2){
        ForgetViewController *vc = [[ForgetViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    
    }else if (indexPath.row == 3){
        UserSecurityController *VC = [[UserSecurityController alloc] init];
        VC.deviceProtect = _model.deviceProtect;
        [self.navigationController pushViewController:VC animated:YES];
    }
    

}

@end
